//
//  QKHomeTableViewCell.m
//  QKWeibo-OC
//
//  Created by iMac_Kurt on 16/9/1.
//  Copyright © 2016年 Kurt_Qi. All rights reserved.
//

#import "QKHomeTableViewCell.h"
#import "QKStatusCellTopView.h"
#import "QKStatusCellBottomView.h"
#import <Masonry.h>
#import "QKStatusCellTopView.h"
#import "QKStatusCellBottomView.h"
#import "UILabel+QKLabel.h"

@interface QKHomeTableViewCell ()
/// 顶部视图
@property (nonatomic, strong) QKStatusCellTopView *topView;
/// 微博文字内容
@property (nonatomic, strong) UILabel *contentLabel;
/// 底部视图
@property (nonatomic, strong) QKStatusCellBottomView *bottomView;
/// cell间隔view
@property (nonatomic, strong) UIView *separateView;

@end

@implementation QKHomeTableViewCell

// 设置数据
- (void)setStatusViewModel:(QKStatusViewModel *)statusViewModel {
    _statusViewModel = statusViewModel;
    
    // 讲数据传给topView
    self.topView.statusViewModel = statusViewModel;
    
    // 内容文字
    self.contentLabel.text = statusViewModel.status.text;
    
}

/// Cell的指定构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //
        [self setupUI];
    }
    return self;
}

/// 设置界面
- (void)setupUI {
    
    // 添加子控件
    
    [self addSubview:self.separateView];
    
    [self addSubview:self.topView];
    [self addSubview:self.contentLabel];
    [self addSubview:self.bottomView];
    
    // 自动布局
    // 分隔view
    [self.separateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@(QKStatusCellMargin));
    }];
    // 顶部视图
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.separateView.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@(2 * QKStatusCellMargin + QKStatusCellIconWidth));
    }];
    
    // 内容Label
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom).offset(QKStatusCellMargin);
        make.left.equalTo(self.topView.mas_left).offset(QKStatusCellMargin);
        
    }];
    
    // 底部视图
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(QKStatusCellMargin);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
#warning TODO: setup bottom view height
        make.height.equalTo(@44);
        make.bottom.equalTo(self.mas_bottom);
    }];
}

#pragma mark - 懒加载控件
- (QKStatusCellTopView *)topView {
    if (_topView == nil) {
        _topView = [[QKStatusCellTopView alloc] init];
    }
    return _topView;
}

- (UILabel *)contentLabel {
    if (_contentLabel == nil) {
        _contentLabel = [UILabel labelWithText:@"内容" fontSize:15 screenInset:QKStatusCellMargin];
    }
    return _contentLabel;
}

- (QKStatusCellBottomView *)bottomView {
    if (_bottomView == nil) {
        _bottomView = [[QKStatusCellBottomView alloc] init];
    }
    return _bottomView;
}

- (UIView *)separateView {
    if (_separateView == nil) {
        UIView *v = [[UIView alloc] init];
        v.backgroundColor = [UIColor lightGrayColor];
        _separateView = v;
    }
    return _separateView;
}
@end
